<!doctype html>
<html lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>focus-within实现tab切换</title>
  <!--  <link rel="stylesheet" href="./styles/index.css">-->
</head>
<style>
  .container {
    width: 300px;
    margin: 50px auto;
    padding: 10px;
    boder: 1px solid #ddd;
  }

  .nav-box {
    font-size: 0;
  }

  button {
    width: 150px;
    height: 64px;
    box-sizing: border-box;
    outline: none;
    background: #fff;
    border: 1px solid #ddd;
    font-size: 18px;
    cursor: pointer;
  }

  button:focus-within {
    color: #fff;
    background: #ffcc00;
  }

  .content-box {
    font-size: 24px;
    border: 1px solid #ddd;
    height: 100px;
  }
  .content-box div {
    display: none;
  }

  /* 默认显示A */
  .nav-box:not(:focus-within) .nav-A {
    color: #fff;
    background: #ffcc00;
  }
  .nav-box:not(:focus-within) .content-A {
    display: block;
  }

  .nav-A:focus-within ~ .content-box .content-A {
    display: block;
  }

  .nav-B:focus-within ~ .content-box .content-B {
    display: block;
  }

</style>
<body>
<p>:focus和:focus-within都可用于button</p>
<div class="container">
  <div class="nav-box">
    <button class="nav-A">Tab-A</button>
    <button class="nav-B">Tab-B</button>
    <div class="content-box">
      <div class="content-A">
        content-A
      </div>
      <div class="content-B">
        content-B
      </div>
    </div>
  </div>
</div>
</body>
</html>
